using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace JYJ.AiYard.Migrations
{
    public partial class AddEntityWechatAppConfig : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SubscriptionPayments_Editions_EditionId",
                schema: "ABP",
                table: "SubscriptionPayments");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SubscriptionPayments",
                schema: "ABP",
                table: "SubscriptionPayments");

            migrationBuilder.RenameTable(
                name: "SubscriptionPayments",
                schema: "ABP",
                newName: "AppSubscriptionPayments");

            migrationBuilder.RenameIndex(
                name: "IX_SubscriptionPayments_Status_CreationTime",
                table: "AppSubscriptionPayments",
                newName: "IX_AppSubscriptionPayments_Status_CreationTime");

            migrationBuilder.RenameIndex(
                name: "IX_SubscriptionPayments_PaymentId_Gateway",
                table: "AppSubscriptionPayments",
                newName: "IX_AppSubscriptionPayments_PaymentId_Gateway");

            migrationBuilder.RenameIndex(
                name: "IX_SubscriptionPayments_EditionId",
                table: "AppSubscriptionPayments",
                newName: "IX_AppSubscriptionPayments_EditionId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_AppSubscriptionPayments",
                table: "AppSubscriptionPayments",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "WechatAppConfigs",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    AppId = table.Column<string>(maxLength: 250, nullable: true),
                    AppSecret = table.Column<string>(maxLength: 250, nullable: true),
                    Token = table.Column<string>(maxLength: 250, nullable: true),
                    EncodingAESKey = table.Column<string>(maxLength: 500, nullable: true),
                    Name = table.Column<string>(maxLength: 50, nullable: true),
                    AppOrgId = table.Column<string>(maxLength: 250, nullable: true),
                    AppType = table.Column<int>(nullable: false),
                    QRCodeUrl = table.Column<string>(maxLength: 250, nullable: true),
                    TenantId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WechatAppConfigs", x => x.Id);
                });

            migrationBuilder.AddForeignKey(
                name: "FK_AppSubscriptionPayments_Editions_EditionId",
                table: "AppSubscriptionPayments",
                column: "EditionId",
                principalSchema: "ABP",
                principalTable: "Editions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_AppSubscriptionPayments_Editions_EditionId",
                table: "AppSubscriptionPayments");

            migrationBuilder.DropTable(
                name: "WechatAppConfigs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_AppSubscriptionPayments",
                table: "AppSubscriptionPayments");

            migrationBuilder.RenameTable(
                name: "AppSubscriptionPayments",
                newName: "SubscriptionPayments",
                newSchema: "ABP");

            migrationBuilder.RenameIndex(
                name: "IX_AppSubscriptionPayments_Status_CreationTime",
                schema: "ABP",
                table: "SubscriptionPayments",
                newName: "IX_SubscriptionPayments_Status_CreationTime");

            migrationBuilder.RenameIndex(
                name: "IX_AppSubscriptionPayments_PaymentId_Gateway",
                schema: "ABP",
                table: "SubscriptionPayments",
                newName: "IX_SubscriptionPayments_PaymentId_Gateway");

            migrationBuilder.RenameIndex(
                name: "IX_AppSubscriptionPayments_EditionId",
                schema: "ABP",
                table: "SubscriptionPayments",
                newName: "IX_SubscriptionPayments_EditionId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SubscriptionPayments",
                schema: "ABP",
                table: "SubscriptionPayments",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_SubscriptionPayments_Editions_EditionId",
                schema: "ABP",
                table: "SubscriptionPayments",
                column: "EditionId",
                principalSchema: "ABP",
                principalTable: "Editions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
